package pro.cherish.smartfile.config.filter;

import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import pro.cherish.smartfile.common.constant.CommonConstants;
import reactor.core.publisher.Mono;

import java.util.UUID;

/**
 * @author 创建人：lys
 * @version 版本号：V1.0
 * <p>
 * ***************************修订记录************************************
 * 2020-6-3 lys 创建该类功能。
 * **********************************************************************
 * </p>
 * @ClassName 类名：LogFilter
 * @Description 功能说明：日志过滤器，打印请求地址并将链路跟踪编号放入线程域中
 * <p>
 *
 * </p>
 * **********************************************************************
 * @date 创建日期： 2020-6-3
 */
@Component
@Order(0)
@Slf4j
public class LogFilter implements WebFilter {
    @Override
    public Mono<Void> filter(ServerWebExchange exchange, WebFilterChain chain) {
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        MDC.put(CommonConstants.SESSION_ID, uuid);
        return chain.filter(exchange);
    }

}
